<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/element-ui.css">
    <script src="js/vue.js"></script>
    <script src="js/element-ui.js"></script>
</head>
<body>
    <div id="app" style="width: 60%; margin:0px auto; margin-top:100px;">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="账号" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="ruleForm.password"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
            <el-input v-model="ruleForm.email"></el-input>
        </el-form-item>
        <el-form-item label="电话号" prop="phone">
            <el-input type="number" v-model="ruleForm.phone"></el-input>
        </el-form-item>
        
        <el-form-item>
            <el-button type="primary" @click="submitForm()">立即创建</el-button>
            <el-button @click="resetForm()">重置</el-button>
        </el-form-item>
        </el-form>
    </div>

    <script>
        new Vue({
            el:"#app",
            data: {
                ruleForm: {
                    name: '',
                    password: '',
                    email: '',
                    phone: ''
                },
                rules: {
                    name: [
                        { required: true, message: '请输入账号' ,trigger:'blur'},
                        {pattern:/^[a-z0-9_-]{6,18}$/, message: '账号名格式错误',trigger:'blur',}
                    ],
                    password: [
                        { required: true, message: '请填写密码',trigger:'blur'},
                        { min: 6, max: 12, message: '长度在 6 到 12 个字符',trigger:'blur'}
                    ],
                    email: [
                        { required: true, message: '请输入邮箱地址',trigger:'blur'},
                        { pattern:/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ , message: '请输入正确的邮箱地址',trigger:'blur'}
                    ],
                    phone: [
                        { required: true, message: '请填写电话',trigger:'blur'},
                        { pattern:/^[1][358][0-9]{9}$/, message: '电话号码格式错误',trigger:'blur'}
                    ]
                }
            },
            methods:{
                submitForm() {
                    this.$refs["ruleForm"].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                    });
                },
                resetForm() {
                    this.$refs["ruleForm"].resetFields();
                }
            }
        })
    </script>
</body>
</html>